package com.lin.subject.infra.basic.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lin.subject.commom.enums.IsDeletedFlagEnum;
import com.lin.subject.infra.basic.entity.SubjectBrief;
import com.lin.subject.infra.basic.service.SubjectBriefService;
import com.lin.subject.infra.basic.mapper.SubjectBriefDao;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * @author jeremylin
 * @description 针对表【subject_brief(简答题)】的数据库操作Service实现
 * @createDate 2024-10-21 11:12:20
 */
@Service
public class SubjectBriefServiceImpl extends ServiceImpl<SubjectBriefDao, SubjectBrief>
        implements SubjectBriefService {

    /**
     * 插入单条数据
     *
     * @param subjectBrief
     */
    @Override
    public void insertOne(SubjectBrief subjectBrief) {
        this.save(subjectBrief);
    }

    /**
     * 根据条件查询
     *
     * @param subjectBrief
     * @return
     */
    @Override
    public List<SubjectBrief> queryListByCondition(SubjectBrief subjectBrief) {
        return lambdaQuery()
                .eq(Objects.nonNull(subjectBrief.getSubjectId()),
                        SubjectBrief::getSubjectId,
                        subjectBrief.getSubjectId())
                .list();
    }

    /**
     * 根据条件查询-单条
     *
     * @param subjectBrief
     * @return
     */
    @Override
    public SubjectBrief queryOneByCondition(SubjectBrief subjectBrief) {
        return lambdaQuery()
                .eq(Objects.nonNull(subjectBrief.getSubjectId()),
                        SubjectBrief::getSubjectId,
                        subjectBrief.getSubjectId())
                .one();
    }

    /**
     * 删除题目
     *
     * @param id
     */
    @Override
    public void deleteSubject(Long id) {
        UpdateWrapper<SubjectBrief> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda().set(SubjectBrief::getIsDeleted, IsDeletedFlagEnum.DELETED.getCode())
                .eq(SubjectBrief::getSubjectId, id);

        this.update(updateWrapper);
    }
}




